// import back from '../../../../component/goback/index.vue'
import { Editor, Toolbar } from "@wangeditor/editor-for-vue";
export default {
  components: {
    Editor,
    Toolbar,
    VueNeditorWrap: () =>
      import("../../../../component/vue-neditor/lib/index.vue"),
    // back
  },
  data() {
    return {
      status: true,
      model: "",
      add: "",
      imageUrl: "",
      editorContent: "",
      opinionId: "",
      title: "",
      toolbarConfig: {},
      editorConfig: {
        placeholder: "请输入内容...",
        MENU_CONF: {
          uploadImage: {
            server: "/system/v1/common/fileUpload",
            fieldName: "filecontent",
            maxFileSize: 5 * 1024 * 1024, // MaxFileLength: 50, // showBase64:true, // maxNumberOfFiles: 3,
            allowedFileTypes: ["image/jpeg", "image/jpg", "image/png"],
            onSuccess(file, res) {},
            onFailed(file, res) {
              console.log(`${file.name} 上传失败`, res);
              localStorage.setItem("url", res.data.fileurl);
            },
            customInsert(res, insertFn) {
              // 因为自定义插入导致onSuccess与onFailed回调函数不起作用,自己手动处理
              // 先关闭等待的Message
              localStorage.setItem("url", res.data.fileurl);
              console.log(res);
              console.log(this);

              setTimeout(() => {
                insertFn(res.data.fileurl, res.data.fileurl);
              }, 1500);
            },
          },
        },
      },
      editor: {
        customConfig: {
          uploadImgServer: "/system/v1/common/upload",
        },
      },
      mode: "default",
      content: "",
      problemid: "", //问题编码
      total: 0,
      insertdate: "",

      form: {
        list: [],
        // problemid: '',
        title: "",
        solution: "",
        type: "",
      },
      pagenum: 1, //查询页码
      pagesize: 10,
      text: {
        problemid: "",
        title: "",
        solution: "",
        type: "",
      },
      myConfig: {
        // 如果需要上传功能,找后端小伙伴要服务器接口地址
        serverUrl: "/system/v1/common/upload",
        // 你的UEditor资源存放的路径,相对于打包后的index.html
        UEDITOR_HOME_URL: "./assets/NEditor/",
        // 编辑器不自动被内容撑高
        autoHeightEnabled: false,
        // 初始容器高度
        initialFrameHeight: 240,
        // 初始容器宽度
        initialFrameWidth: "100%",
        // 关闭自动保存
        enableAutoSave: false,
      },
      contents: "", //副文本初始化的内容
    };
  },
  created() {
    this.geteData();
  },
  mounted() {},
  methods: {
    onChange(data) {
      console.log(this.$refs.editor);
    },
    onChanges(data) {
      console.log(data);
    },
    onCreated(editor) {
      this.editor = Object.seal(editor); // 一定要用 Object.seal() ，否则会报错
    },
    // 获取和设置富文本内容
    ready(editorInstance) {
      // editorInstance.setContent(this.model.content);
      editorInstance.addListener("contentChange", () => {
        this.text.solution = editorInstance.getContent();
      });
    },
    newAdd() {
      this.status = false;
      this.text.problemid = "";
      this.text.title = "";
      this.text.solution = "";
      this.text.type = "";
    },
    details(obj) {
      this.$router.push({
        path: "./feedback/detailed",
        query: {
          problemid: obj,
          item: 8,
        },
      });
    },
    geteData() {
      this.$axios
        .$post("/app/v1/platform/problem/list", {
          pagenum: this.pagenum,
          pagesize: this.pagesize,
        })
        .then((res) => {
          this.form = res.data.data;
          this.total = parseInt(res.data.data.totalnum);
        });
    },
    outPut() {
      if (this.text.title == "") {
        this.$message({
          type: "error",
          message: "提交失败标题不能为空",
        });
        return;
      }
      if (this.text.type == "") {
        this.$message({
          type: "error",
          message: "提交问题类型不能为空",
        });
        return;
      } else if (this.text.solution == "") {
        this.$message({
          type: "error",
          message: "提交内容不能为空",
        });
        return;
      }
      this.$confirm("是否要提交?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.$axios
          .$post("/app/v1/platform/problem/updateAndInsert", this.text)
          .then((res) => {
            if (res.data.code === 1) {
              this.$message({
                type: "success",
                message: "新增成功",
              });
              (this.status = true), this.geteData();
            } else {
              this.$message({
                type: "error",
                message: res.data.message,
              });
            }
          });
      });
    },

    //取消
    cancel() {
      this.status = true;
    },

    //分页查询
    handleCurrentChange(val) {
      this.pagenum = val;
      this.geteData();
    },
    handleSizeChange(val) {
      this.pagesize = val;
      this.pagenum = 1;
      this.geteData();
    },
  },
};
